<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <button>write</button>

  <script>
    // 向文档流写入内容
    document.write('<p>Hello world!</p>')

    function write() {
      // 写入时文档流已关闭，会先调用 document.open() 打开文档流再进行写入，导致文档已有内容被清空
      document.write('<p>Hello world!</p>')
    }

    document.querySelector('button').addEventListener('click', write)
  </script>
</body>

</html>